#ifndef GHTTP_H
#define GHTTP_H

#include <ghttp_constants.h>
#include <time.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef struct _ghttp_request ghttp_request;

typedef enum ghttp_type_tag
{
    ghttp_type_get = 0,
    ghttp_type_options,
    ghttp_type_head,
    ghttp_type_post,
    ghttp_type_put,
    ghttp_type_delete,
    ghttp_type_trace,
    ghttp_type_connect,
    ghttp_type_propfind,
    ghttp_type_proppatch,
    ghttp_type_mkcol,
    ghttp_type_copy,
    ghttp_type_move,
    ghttp_type_lock,
    ghttp_type_unlock
} ghttp_type;

typedef enum ghttp_sync_mode_tag
{
    ghttp_sync = 0,
    ghttp_async
} ghttp_sync_mode;

typedef enum ghttp_status_tag
{
    ghttp_error = -1,
    ghttp_not_done,
    ghttp_done
} ghttp_status;

typedef enum ghttp_proc_tag
{
    ghttp_proc_none = 0,
    ghttp_proc_request,
    ghttp_proc_response_hdrs,
    ghttp_proc_response
} ghttp_proc;

/* create a new request object */
ghttp_request *
ghttp_request_new(void);



/* Set a uri in a request
 * This will return -1 if the uri is invalid
 */

int
ghttp_set_uri(ghttp_request *a_request, char *a_uri);


/* Set a request type
 * This will return -1 if the request type is invalid or
 * unsupported
 */

int
ghttp_set_type(ghttp_request *a_request, ghttp_type a_type);

/* Set the body.
 * This will return -1 if the request type doesn't support it
 */

int
ghttp_set_body(ghttp_request *a_request, char *a_body, int a_len);

/* Set whether or not you want to use sync or async mode.
 */

int
ghttp_set_sync(ghttp_request *a_request,
                        ghttp_sync_mode a_mode);

/* Prepare a request.
 * Call this before trying to process a request or if you change the
 * uri.
 */

int
ghttp_prepare(ghttp_request *a_request);


/* Set a random request header
 */

void
ghttp_set_header(ghttp_request *a_request,
                            const char *a_hdr, 
                            const char *a_val);

/* Process a request
 */

ghttp_status
ghttp_process(ghttp_request *a_request);


/* Clean a request
 */
void
ghttp_clean(ghttp_request *a_request);


/* get the return entity body
 */

char *
ghttp_get_body(ghttp_request *a_request);

/* get the returned length
 */

int
ghttp_get_body_len(ghttp_request *a_request);


/* Return the status code.
 */

int
ghttp_status_code(ghttp_request *a_request);


#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* GHTTP_H */
